/**
 * 
 */
package com.scpii.universal.pns.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.scpii.universal.hibernate.dao.impl.BaseDaoImpl;
import com.scpii.universal.pns.dao.EcOrderDetailsDao;
import com.scpii.universal.pns.dto.EcOrderDetailsDto;
import com.scpii.universal.pns.dto.EcOrderSearchDto;
import com.scpii.universal.pns.entity.EcOrderDetails;

/**
 * genericWeb
 * 
 * @author acer 2012-7-5下午04:35:11
 */
@Repository
public class EcOrderDetailsDaoImpl extends BaseDaoImpl<EcOrderDetails, Long>
		implements EcOrderDetailsDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<EcOrderDetailsDto> getAllByProSN(EcOrderSearchDto condition,
			Long produceId) {
		StringBuffer hql = new StringBuffer(
				"select new com.scpii.universal.pns.dto.EcOrderDetailsDto(e,p) from EcOrderDetails e,EcProduct p "
						+ "where e.productId=p.id and e.orderId=?");
		if (condition.getProductIsReal() >= 0) {
			hql.append(" and p.isReal=?");
			return getHibernateTemplate().getSessionFactory()
					.getCurrentSession().createQuery(hql.toString())
					.setParameter(0, produceId)
					.setParameter(1, condition.getProductIsReal()).list();
		}
		return getHibernateTemplate().getSessionFactory().getCurrentSession()
				.createQuery(hql.toString()).setParameter(0, produceId).list();
	}

}
